'use strict';

var DataLoader = DataLoader || {};

DataLoader.Profile = (function() {
	
	function Profile () {
	}

	Profile.prototype.withLoginUrl = function (loginUrl) {
		this.loginUrl = loginUrl;
		return this;
	};

	Profile.prototype.withServiceUrl = function (serviceUrl) {
		this.serviceUrl = serviceUrl;
		return this;		
	};

	Profile.prototype.withServerUrl = function (serverUrl) {
		this.serverUrl = serverUrl;
		return this;		
	};	

	Profile.prototype.withLogin = function (login) {
		this.login = login;
		return this;		
	};	
	
	Profile.prototype.withPassword = function (password) {
		this.password = password;
		return this;		
	};		

	Profile.prototype.withToken = function (token) {
		this.token = token;
		return this;		
	};
	
	return Profile;
	
})();

DataLoader.SalesForceProfile = (function() {
	
	function SalesForceProfile() {
		
		this.connectionTypes = {
				'PRE-PROD' : {  loginUrl   : 'https://test.salesforce.com/services/Soap/u/32.0'
								, serviceUrl : 'https://cs7.salesforce.com/services/Soap/u/32.0'
								, serverUrl  : 'https://cs7.salesforce.com' , name : 'Pré-Produção' },
				'PROD': {  loginUrl   : 'https://login.salesforce.com/services/Soap/u/32.0'
						 , serviceUrl : 'https://na9.salesforce.com/services/Soap/u/32.0'
						 , serverUrl  : 'https://na9.salesforce.com' , name : 'Produção' 
								},
				'DEV' : {   loginUrl   : 'https://test.salesforce.com/services/Soap/u/32.0'
					, serviceUrl : 'https://cs8.salesforce.com/services/Soap/u/32.0'
					, serverUrl  : 'https://cs8.salesforce.com' , name : 'Desenvolmento'}
		};
		
		this.connection = {};
		
	} 
	
	SalesForceProfile.prototype.createProfileFromTemplate = function (enviroment) {
		var profile = new DataLoader.Profile();
		
		return profile.withLoginUrl (enviroment.loginUrl)
		       		  .withServiceUrl (enviroment.serviceUrl)
		       		  .withServerUrl (enviroment.serverUrl);
		
	};
	
	SalesForceProfile.prototype.enviroments = function () {
		var list = [];
		for (var env in this.connectionTypes) {
			list.push( this.connectionTypes[env] );
		}
		return list;
	};
	
	
	
	return SalesForceProfile;
	
})();